project(jack_client)

IF(NOT FAUST_EXECUTABLE)
  MESSAGE(STATUS "Looking for FAUST")
  FIND_PROGRAM(FAUST_EXECUTABLE faust)
  IF(FAUST_EXECUTABLE)
    MESSAGE(STATUS "Looking for FAUST -- ${FAUST_EXECUTABLE}")
  ENDIF(FAUST_EXECUTABLE)
ENDIF(NOT FAUST_EXECUTABLE)

IF(FAUST_EXECUTABLE)
  MACRO(FAUST_FILE FILENAME)
    GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
    GET_FILENAME_COMPONENT(HEAD "${FILENAME}" NAME_WE)
    SET(OUTFILE "${CMAKE_CURRENT_SOURCE_DIR}/${HEAD}.dsp.in")
    ADD_CUSTOM_COMMAND(
      OUTPUT "${OUTFILE}"
      COMMAND "${FAUST_EXECUTABLE}"
      ARGS -o ${OUTFILE}
      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
  ENDMACRO(FAUST_FILE)
ENDIF(FAUST_EXECUTABLE)

SET(Libraries
  jack
  rt
  pthread
  )

ADD_EXECUTABLE(demo1 demo1.cpp)
TARGET_LINK_LIBRARIES(demo1 ${Libraries})

ADD_EXECUTABLE(demo2 demo2.cpp)
TARGET_LINK_LIBRARIES(demo2 ${Libraries})

ADD_EXECUTABLE(demo3 demo3.cpp)
TARGET_LINK_LIBRARIES(demo3 ${Libraries})

ADD_EXECUTABLE(simple_polyphonic simple_polyphonic.cpp)
TARGET_LINK_LIBRARIES(simple_polyphonic ${Libraries})

ADD_EXECUTABLE(simple_monophonic simple_monophonic.cpp)
TARGET_LINK_LIBRARIES(simple_monophonic ${Libraries})

FAUST_FILE(organ.dsp)
ADD_EXECUTABLE(simple_organ simple_organ.cpp organ.dsp.in)
TARGET_LINK_LIBRARIES(simple_organ ${Libraries})
